package org.csu.mypetstore.api.controller.front;

import org.csu.mypetstore.api.common.CommonResponse;
import org.csu.mypetstore.api.entity.Account;
import org.csu.mypetstore.api.entity.Profile;
import org.csu.mypetstore.api.entity.Signon;
import org.csu.mypetstore.api.service.AccountService;
import org.csu.mypetstore.api.vo.AccountVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/account/")
public class AccountController {

    @Autowired
    private AccountService accountService;

    //登录
    @PostMapping("login")
    @ResponseBody
    public CommonResponse<AccountVO> login(@RequestBody Signon signon) {

        return accountService.login(signon);
    }

    //查询所有用户（仿catagory）
    @GetMapping("users")
    @ResponseBody
    public CommonResponse<List<AccountVO>> getAccountList() {
        return accountService.getAccountList();
    }

    @GetMapping("user/{id}")
    @ResponseBody
    public CommonResponse<AccountVO> getAccountByUserId(@PathVariable("id") String userId) {
        return accountService.getAccountByUserId(userId);
    }

    @GetMapping("user/phone/{phone}")
    @ResponseBody
    public CommonResponse<AccountVO> getAccountByPhone(@PathVariable("phone") String phone) {
        return accountService.getAccountByPhone(phone);
    }

    //查询profile
    @GetMapping("profiles")
    @ResponseBody
    public CommonResponse<List<Profile>> getallAccountprofile() {
        return accountService.getallAccountprofile();
    }

    //添加用户
    @PostMapping("/")
    // public CommonResponse<List<void>> insertAccount(@RequestBody Account account){return accountService.insertAccount(account);}
    //}
    @ResponseBody
    public CommonResponse<String> insertAccount(@RequestBody AccountVO accountVO) {
        return accountService.insertAccount(accountVO);
    }

    //删除用户(没写完)
    @DeleteMapping("/delete")
    @ResponseBody
    public CommonResponse<String> deleteAccount(@RequestBody Account account) {
        return accountService.deleteAccount(account);
    }
    //更新信息
    @PutMapping("update")
    @ResponseBody
    public CommonResponse<String> updateAccount(@RequestBody AccountVO accountVO){
        return accountService.updateAccount(accountVO);
    }
}